<?php
/**
 * Template Name: Add Attendance
 * Description: Attendance Entry
 *
 * @package WordPress
 * @subpackage Immersion
 * @since Immersion 1.0
 */

get_header( 'trainer' );
$hostname_CrossFit = "localhost";
$database_CrossFit = "quadnips_CF26AppsDev";
$username_CrossFit = "quadnips_26";
$password_CrossFit = "fearless";
$CrossFit = mysql_pconnect($hostname_CrossFit, $username_CrossFit, $password_CrossFit) or trigger_error(mysql_error(),E_USER_ERROR); 


?>
 
 <?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}



	


mysql_select_db($database_CrossFit, $CrossFit);
$query_MemberList = "SELECT Name FROM Members ORDER BY Name ASC";
$MemberList = mysql_query($query_MemberList, $CrossFit) or die(mysql_error());
$row_MemberList = mysql_fetch_assoc($MemberList);
$totalRows_MemberList = mysql_num_rows($MemberList);
$query_MemberList = "SELECT Name FROM Members WHERE ID <= 25 ORDER BY Name ASC";
$MemberList = mysql_query($query_MemberList, $CrossFit) or die(mysql_error());
$row_MemberList = mysql_fetch_assoc($MemberList);
$totalRows_MemberList = mysql_num_rows($MemberList);

mysql_select_db($database_CrossFit, $CrossFit);
$query_MemberListGreaterThan25 = "SELECT Name FROM Members WHERE ID > 25 ORDER BY Name ASC";
$MemberListGreaterThan25 = mysql_query($query_MemberListGreaterThan25, $CrossFit) or die(mysql_error());
$row_MemberListGreaterThan25 = mysql_fetch_assoc($MemberListGreaterThan25);
$totalRows_MemberListGreaterThan25 = mysql_num_rows($MemberListGreaterThan25);

mysql_select_db($database_CrossFit, $CrossFit);
$query_ClassTypes = "SELECT ClassType FROM ClassType ORDER BY ID ASC";
$ClassTypes = mysql_query($query_ClassTypes, $CrossFit) or die(mysql_error());
$row_ClassTypes = mysql_fetch_assoc($ClassTypes);
$totalRows_ClassTypes = mysql_num_rows($ClassTypes);

mysql_select_db($database_CrossFit, $CrossFit);
$query_ClassTimes = "SELECT Class_Times FROM classtimes ORDER BY ID ASC";
$ClassTimes = mysql_query($query_ClassTimes, $CrossFit) or die(mysql_error());
$row_ClassTimes = mysql_fetch_assoc($ClassTimes);
$totalRows_ClassTimes = mysql_num_rows($ClassTimes);

mysql_select_db($database_CrossFit, $CrossFit);
$query_MembersListView = "SELECT Name FROM member_list WHERE `Name_Filter` = 1 ORDER BY Name ASC";
$MembersListView = mysql_query($query_MembersListView, $CrossFit) or die(mysql_error());
$row_MembersListView = mysql_fetch_assoc($MembersListView);
$totalRows_MembersListView = mysql_num_rows($MembersListView);

mysql_select_db($database_CrossFit, $CrossFit);
$query_MembersListViewM = "SELECT Name FROM member_list WHERE `Name_Filter` = 0 ORDER BY Name ASC";
$MembersListViewM = mysql_query($query_MembersListViewM, $CrossFit) or die(mysql_error());
$row_MembersListViewM = mysql_fetch_assoc($MembersListViewM);
$totalRows_MembersListViewM = mysql_num_rows($MembersListViewM);

mysql_select_db($database_CrossFit, $CrossFit);
$query_CUR_DATE = "SELECT CURDATE() FROM classtimes";
$CUR_DATE = mysql_query($query_CUR_DATE, $CrossFit) or die(mysql_error());
$row_CUR_DATE = mysql_fetch_assoc($CUR_DATE);
$totalRows_CUR_DATE = mysql_num_rows($CUR_DATE);
?>

		<div id="primary" class="full-width">
        

			<div id="content" role="main">

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
	<header class="entry-header">
		<?php do_action( 'gpp_before_title' ); ?>
		<h1 class="entry-title"><?php the_title(); ?></h1>
			
	</header><!-- .entry-header -->

	<div class="entry-content">
		<p><div id="datepicker2"></div><!-- End demo --></p>

<!--<p><a href="addwodscore.php">Add WOD Scores to Today's Attendance </a>(BETA, not working yet)</p>-->


<?php 
$checkboxMember3 = $_POST['membernames'];
$checkboxMember4 = $_POST['membernames2'];
 if (count($_POST)>0) echo "<h3>Recently entered names:</h3> <br>"; 
for ($i=0; $i<sizeof($checkboxMember3); $i++){
print_r($checkboxMember3[$i].'<br>');
}
for ($i=0; $i<sizeof($checkboxMember4); $i++){
print_r($checkboxMember4[$i].'<br>');
}


?>
<form action="http://development.crossfit26.com/process/addattendanceprocess.php" method="POST" name="form1" id="form1">
  <table width="600" border="0">
    <tr>
      <td>
      <p><label for="datepicker">Select Class Date: </label><br /><input name="datepicker" type="text" id="datepicker" value="<?php echo $row_CUR_DATE['CURDATE()']; ?>" readonly="readonly">
      
      
      
      
      
      </p>
      <p><strong>Select the class type: 
        </strong><br />
        <?php do { ?>
          <input name="classtyperadio" type="radio" id="<?php echo $row_ClassTypes['ClassType']; ?>" value="<?php echo $row_ClassTypes['ClassType']; ?>" />
          <label for="<?php echo $row_ClassTypes['ClassType']; ?>"><?php echo $row_ClassTypes['ClassType']; ?></label>
           &nbsp;&nbsp;&nbsp;
          <?php } while ($row_ClassTypes = mysql_fetch_assoc($ClassTypes)); ?>
      </p>
        
        <p>
          <strong>Select class time:</strong><br />
          
          <?php do { ?>
          
            <input type="radio" name="classtimesradio" id="<?php echo $row_ClassTimes['Class_Times']; ?>" value="<?php echo $row_ClassTimes['Class_Times']; ?>" />
            <label for="<?php echo $row_ClassTimes['Class_Times']; ?>"><?php echo $row_ClassTimes['Class_Times']; ?></label>
            <br />
            
            <?php } while ($row_ClassTimes = mysql_fetch_assoc($ClassTimes)); ?>
      
      </p></td>
    </tr>
  </table>
  
  <p><strong>Athlete Names</strong></p>
  <p>If you don't see a name in the list and the person is clearly a member, click <a href="addathlete.php">Add Athlete</a>, otherwise record them as a drop in.</p>
  <p><input name="DropIn" type="checkbox" value="Drop In" /><label for="Drop In"> Drop In  &nbsp;&nbsp;</label><select name="DropInCount" size="1" id="DropInCount">
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    <option value="4">4</option>
    <option value="5">5</option>
    </select></p>
  <table width="500" border="0">
    <tr>
      <td valign="top" ><?php do { ?>
          <table  border="0"   cellpadding="6" cellspacing="3">
            <tr>
              <td valign="top" height="25" width="250">
                <input type="checkbox" name="membernames[]"  value="<?php echo $row_MembersListView['Name']; ?>" id="<?php echo $row_MembersListView['Name']; ?>" />
               <label for="<?php echo $row_MembersListView['Name']; ?>"> <?php echo $row_MembersListView['Name']; ?></label>
                <br /></td>
            </tr>
          </table>
      <?php } while ($row_MembersListView = mysql_fetch_assoc($MembersListView)); ?></td>
      <td valign="top"><?php do { ?>
          <table  border="0"   cellpadding="6" cellspacing="3">
            <tr>
              <td valign="top" height="25" width="250"><input type="checkbox" name="membernames2[]"  value="<?php echo $row_MembersListViewM['Name']; ?>" id="<?php echo $row_MembersListViewM['Name']; ?>"/>
               <label for="<?php echo $row_MembersListViewM['Name']; ?>"> <?php echo $row_MembersListViewM['Name']; ?></label><br /></td>
            </tr>
          </table>
      <?php } while ($row_MembersListViewM = mysql_fetch_assoc($MembersListViewM)); ?></td>
    </tr>
  </table>    
<br />
    
    <input class="button" type="submit" name="Submit" id="Submit" value="Submit" />&nbsp;&nbsp;&nbsp;
    <input class="button" type="reset" name="reset" id="reset" value="Reset" />
    <br />
  </p>
<p>&nbsp;</p>
  <input type="hidden" name="MM_insert" value="form1" />
</form>


<?php
mysql_free_result($MemberList);

mysql_free_result($MemberListGreaterThan25);

mysql_free_result($ClassTypes);

mysql_free_result($ClassTimes);

mysql_free_result($MembersListView);

mysql_free_result($MembersListViewM);

mysql_free_result($CUR_DATE);
?>
        
        
	</div><!-- .entry-content -->
</article><!-- #post-<?php the_ID(); ?> -->


                
			</div><!-- #content -->
          

		</div><!-- #primary -->

<?php get_footer(); ?>